package com.yuelan.codelib.utils;

import java.io.File;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class ShareUtil {
	/**
	 * 作者: peijiangping<BR>
	 * 时间:2013-6-20上午11:55:52<BR>
	 * 功能:分享图片到指定包名<BR>
	 * 返回值:void<BR>
	 */
	public static void sharedLocalAppPic(Context c, String path, String con,
			String packagename) {
		File file = new File(path);
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("image/jpeg");
		intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
		intent.putExtra(Intent.EXTRA_TEXT, con);
		if (TextUtil.notNull(packagename)) {
			if (AppUtil.checkApkExist(c, packagename)) {
				intent.setPackage(packagename);
			}
		}
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		c.startActivity(intent);
	}

	/**
	 * 作者: peijiangping<BR>
	 * 时间:2013-6-20上午11:55:52<BR>
	 * 功能:分享图片到指定包名<BR>
	 * 返回值:void<BR>
	 */
	public static void sharedLocalAppPic(Context c, Uri uri, String con,
			String packagename) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("image/jpeg");
		intent.putExtra(Intent.EXTRA_STREAM, uri);
		intent.putExtra(Intent.EXTRA_TEXT, con);
		if (TextUtil.notNull(packagename)) {
			if (AppUtil.checkApkExist(c, packagename)) {
				intent.setPackage(packagename);
			}
		}
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		c.startActivity(intent);
	}

	/**
	 * 作者: peijiangping<BR>
	 * 时间:2013-6-20上午11:55:52<BR>
	 * 功能:分享文字到指定包名<BR>
	 * 返回值:void<BR>
	 */
	public static void sharedLocalAppTxt(Context c, String con,
			String packagename) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("text/plain");
		intent.putExtra(Intent.EXTRA_SUBJECT, "Share");
		intent.putExtra(Intent.EXTRA_TEXT, con);
		if (TextUtil.notNull(packagename)) {
			if (AppUtil.checkApkExist(c, packagename)) {
				intent.setPackage(packagename);
			}
		}
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		c.startActivity(intent);
	}
}
